home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / text / html / parser / DocumentParser.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  3.9 KB  |  122 lines

  1. package javax.swing.text.html.parser;
  2.  
  3. import java.io.IOException;
  4. import java.io.Reader;
  5. import javax.swing.text.ChangedCharSetException;
  6. import javax.swing.text.SimpleAttributeSet;
  7. import javax.swing.text.html.HTML;
  8. import javax.swing.text.html.HTMLEditorKit;
  9. import javax.swing.text.html.HTML.Attribute;
  10.  
  11. public class DocumentParser extends Parser {
  12.    private int inbody;
  13.    private int intitle;
  14.    private int inhead;
  15.    private int instyle;
  16.    private boolean seentitle;
  17.    private HTMLEditorKit.ParserCallback callback = null;
  18.    private boolean ignoreCharSet = false;
  19.    private static final boolean debugFlag = false;
  20.    private static HTML.UnknownTag EndOfLineTag = new HTML.UnknownTag("__EndOfLineTag__");
  21.  
  22.    public DocumentParser(DTD var1) {
  23.       super(var1);
  24.    }
  25.  
  26.    private void debug(String var1) {
  27.       System.out.println(var1);
  28.    }
  29.  
  30.    protected void handleComment(char[] var1) {
  31.       this.callback.handleComment(var1, ((Parser)this).getCurrentPos());
  32.    }
  33.  
  34.    protected void handleEmptyTag(TagElement var1) throws ChangedCharSetException {
  35.       Element var2 = var1.getElement();
  36.       if (var2 == super.dtd.meta && !this.ignoreCharSet) {
  37.          SimpleAttributeSet var3 = ((Parser)this).getAttributes();
  38.          if (var3 != null) {
  39.             String var4 = (String)var3.getAttribute(Attribute.CONTENT);
  40.             if (var4 != null) {
  41.                if ("content-type".equalsIgnoreCase((String)var3.getAttribute(Attribute.HTTPEQUIV))) {
  42.                   throw new ChangedCharSetException(var4, false);
  43.                }
  44.  
  45.                if ("charset".equalsIgnoreCase((String)var3.getAttribute(Attribute.HTTPEQUIV))) {
  46.                   throw new ChangedCharSetException(var4, true);
  47.                }
  48.             }
  49.          }
  50.       }
  51.  
  52.       if (this.inbody != 0 || var2 == super.dtd.meta || var2 == super.dtd.base || var2 == super.dtd.isindex || var2 == super.dtd.style || var2 == super.dtd.link) {
  53.          if (var1.fictional()) {
  54.             this.callback.handleSimpleTag(var1.getHTMLTag(), new SimpleAttributeSet(), ((Parser)this).getCurrentPos());
  55.          } else {
  56.             this.callback.handleSimpleTag(var1.getHTMLTag(), ((Parser)this).getAttributes(), ((Parser)this).getCurrentPos());
  57.             ((Parser)this).flushAttributes();
  58.          }
  59.       }
  60.  
  61.    }
  62.  
  63.    protected void handleEndTag(TagElement var1) {
  64.       Element var2 = var1.getElement();
  65.       if (var2 == super.dtd.body) {
  66.          --this.inbody;
  67.       } else if (var2 == super.dtd.title) {
  68.          --this.intitle;
  69.          this.seentitle = true;
  70.       } else if (var2 == super.dtd.head) {
  71.          --this.inhead;
  72.       } else if (var2 == super.dtd.style) {
  73.          --this.instyle;
  74.       }
  75.  
  76.       this.callback.handleEndTag(var1.getHTMLTag(), ((Parser)this).getCurrentPos());
  77.    }
  78.  
  79.    protected void handleError(int var1, String var2) {
  80.       this.callback.handleError(var2, ((Parser)this).getCurrentPos());
  81.    }
  82.  
  83.    protected void handleStartTag(TagElement var1) {
  84.       Element var2 = var1.getElement();
  85.       if (var2 == super.dtd.body) {
  86.          ++this.inbody;
  87.       } else if (var2 != super.dtd.html) {
  88.          if (var2 == super.dtd.head) {
  89.             ++this.inhead;
  90.          } else if (var2 == super.dtd.title) {
  91.             ++this.intitle;
  92.          } else if (var2 == super.dtd.style) {
  93.             ++this.instyle;
  94.          }
  95.       }
  96.  
  97.       if (var1.fictional()) {
  98.          this.callback.handleStartTag(var1.getHTMLTag(), new SimpleAttributeSet(), ((Parser)this).getCurrentPos());
  99.       } else {
  100.          this.callback.handleStartTag(var1.getHTMLTag(), ((Parser)this).getAttributes(), ((Parser)this).getCurrentPos());
  101.          ((Parser)this).flushAttributes();
  102.       }
  103.  
  104.    }
  105.  
  106.    protected void handleText(char[] var1) {
  107.       if (var1 != null && (this.inbody != 0 || this.instyle != 0 || this.intitle != 0 && !this.seentitle)) {
  108.          this.callback.handleText(var1, ((Parser)this).getCurrentPos());
  109.       }
  110.  
  111.    }
  112.  
  113.    public void parse(Reader var1, HTMLEditorKit.ParserCallback var2, boolean var3) throws IOException {
  114.       this.ignoreCharSet = var3;
  115.       this.callback = var2;
  116.       ((Parser)this).parse(var1);
  117.       SimpleAttributeSet var4 = new SimpleAttributeSet();
  118.       var4.addAttribute("__EndOfLineString__", ((Parser)this).getEndOfLineString());
  119.       var2.handleSimpleTag(EndOfLineTag, var4, ((Parser)this).getCurrentPos());
  120.    }
  121. }
  122.